export function weekFormat (num) {
    switch (num) {
        case 1:
            return '星期一'
        case 2:
            return '星期二'
        case 3:
            return '星期三'
        case 4:
            return '星期四'
        case 5:
            return '星期五'
        case 6:
            return '星期六'
        case 7:
            return '星期天'
    }
}

export function weekFormatTwo (num) {
    switch (num) {
        case 1:
            return '周一'
        case 2:
            return '周二'
        case 3:
            return '周三'
        case 4:
            return '周四'
        case 5:
            return '周五'
        case 6:
            return '周六'
        case 7:
            return '周天'
    }
}

export function formatBlance (num) {
    return Number(num).toLocaleString()
}

export function getMdHis (originalString) {
    return originalString.slice(5);
}

export function truncateString (str) {
    if (str.length <= 9) {
        return str; // 如果字符串长度小于或等于 maxLength，则返回原始字符串
    } else {
        let start = str.slice(0, 4); // 获取前四个字符
        let end = str.slice(-4); // 获取后四个字符
        return start + '...' + end; // 返回头部、省略号和尾部组合的字符串
    }
}

export function getShortOrder (originalString) {
    return originalString.slice(15);
}
export function getTimeAgo (timestamp) {
    const now = new Date();
    const past = new Date(timestamp);
    const seconds = Math.floor((now - past) / 1000);
    const minutes = Math.floor(seconds / 60);
    const hours = Math.floor(minutes / 60);
    const days = Math.floor(hours / 24);
    const months = Math.floor(days / 30);
    const years = Math.floor(months / 12);

    if (seconds < 60) {
        return "刚刚";
    } else if (minutes < 60) {
        return `${minutes}分钟前`;
    } else if (hours < 24) {
        return `${hours}小时前`;
    } else if (days < 30) {
        return `${days}天前`;
    } else if (months < 12) {
        return `${months}个月前`;
    } else {
        return "1年前";
    }
}


export function timestampToAgo (timestamp) {
    // 时间戳为10位需*1000，时间戳为13位不需乘1000
    var past = new Date(timestamp * 1000);
    const now = new Date();
    const seconds = Math.floor((now - past) / 1000);
    const minutes = Math.floor(seconds / 60);
    const hours = Math.floor(minutes / 60);
    const days = Math.floor(hours / 24);
    const months = Math.floor(days / 30);
    if (seconds < 60) {
        return "刚刚";
    } else if (minutes < 60) {
        return `${minutes}分钟前`;
    } else if (hours < 24) {
        return `${hours}小时前`;
    } else if (days < 30) {
        return `${days}天前`;
    } else if (months < 12) {
        return `${months}个月前`;
    } else {
        return "1年前";
    }
}

export function formatChatDate (timestamp) {
    const now = new Date();
    const targetDate = new Date(timestamp * 1000);

    // 检查是否为今天
    if (
        targetDate.getDate() === now.getDate() &&
        targetDate.getMonth() === now.getMonth() &&
        targetDate.getFullYear() === now.getFullYear()
    ) {
        const hours = targetDate.getHours().toString().padStart(2, '0');
        const minutes = targetDate.getMinutes().toString().padStart(2, '0');
        return hours + ':' + minutes;
    }

    // 检查是否为一年前
    const oneYearAgo = new Date(
        now.getFullYear() - 1,
        now.getMonth(),
        now.getDate()
    );
    if (targetDate < oneYearAgo) {
        return '1年前';
    }

    // 其他情况显示月和日
    const month = targetDate.getMonth() + 1;
    const day = targetDate.getDate();
    return month + '-' + day;
}

export function formatNumber (num) {
    if (num >= 1e3 && num < 1e4) {
        return parseInt(num / 1e3).toFixed(1) + 'K'
    }
    else if (num >= 1e4) {
        return parseInt(num / 1e4).toFixed(1) + 'w'
    }
    else {
        return num
    }
}

export function formatTime (seconds) {
    seconds = Math.round(seconds)
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const remainingSeconds = seconds % 60;
    let format;
    if (hours >= 1) {
        format = "HH:II:SS";
    } else {
        format = "II:SS";
    }
    let timeString = "";
    if (format === "HH:II:SS") {
        timeString = `${hours.toString().padStart(2, "0")}:${minutes
            .toString()
            .padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
    } else if (format === "II:SS") {
        timeString = `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`;
    }

    return timeString;
}

// function formatNumber(number) {
//     if (number < 1000) {
//       return number.toString();
//     } else if (number < 10000) {
//       const kilo = (number / 1000).toFixed(1);
//       return kilo + '千';
//     } else {
//       const tenThousand = (number / 10000).toFixed(1);
//       return tenThousand + '万';
//     }
//   }